﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="ViewMembers.aspx.cs" 
    Inherits="TRL.TRLAdmin.Members.ViewMember" Trace="false"%>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <nav>
        <div id="jCrumbs" class="breadCrumb module">
            <ul>
                <li>
                    <a href="#"><i class="icon-home"></i></a>
                </li>
                <li>
                    Membership Management
                </li>
                <li>
                    View Memberships
                </li>
            </ul>
        </div>
    </nav>

    <div class="page-header">
        <h1>View Memberships <small>Select criteria to view memberships</small></h1>
    </div>

    <div class="row-fluid">
        <div class="span12">
            <div class="well" style="padding-top: 0px">
                <h3>Membership Status</h3>
                    <big>
                        <asp:RadioButton ID="Current" GroupName="status" runat="server" checked="true" /> <span id="currentFields">Current</span>
                        <asp:RadioButton ID="All" GroupName="status" runat="server" /> <span id="allFields">All</span>
                        <br />
                        <asp:RadioButton ID="Expiration" GroupName="status" runat="server" />
                        <span id="expirationFields">
                            Expiration
                            <asp:DropDownList ID="ExpSelector" runat="server">
                                <asp:ListItem Value="Any">Any Date</asp:ListItem>
                                <asp:ListItem Value="LastMonth">Within Last Month</asp:ListItem>
                                <asp:ListItem Value="LastTwoMonths">Within Last Two Months</asp:ListItem>
                                <asp:ListItem Value="LastFourMontsh">Within Last Four Months</asp:ListItem>
                                <asp:ListItem Value="NextMonth">In Next Month</asp:ListItem>
                                <asp:ListItem Value="NextTwoMonths">In Next Two Months</asp:ListItem>
                                <asp:ListItem Value="NextFourMonths">In Next Four Months</asp:ListItem>
                                <asp:ListItem Value="Between">Between</asp:ListItem>
                            </asp:DropDownList>
                            <asp:TextBox runat="server" ID="expStartDate" Width="70" MaxLength="14" />
                            <Juice:Datepicker runat="server" TargetControlID="expStartDate"
                                ButtonImage="/img/calendar-icon.png" ButtonImageOnly="true" ShowOn="both" ButtonText="Show date picker"  />
                            to
                            <asp:TextBox runat="server" ID="expEndDate" Width="70" MaxLength="14" />
                            <Juice:Datepicker ID="Datepicker1" runat="server" TargetControlID="expEndDate"
                            ButtonImage="/img/calendar-icon.png" ButtonImageOnly="true" ShowOn="both" ButtonText="Show date picker"  />
                        </span>
                    </big>
                    <br />
                    <asp:Button ID="ViewMemberships" runat="server" Text="View Memberships" 
                    CssClass="btn btn-primary" onclick="ViewMemberships_Click"/>
                    <asp:Button ID="DownloadCSV" runat="server" Text="Download CSV" 
                    CssClass="btn btn-primary" onclick="DownloadCSV_Click"/>
            </div>
            
        </div>
     </div>
     <hr />
     <div class="row-fluid">
        <asp:GridView ID="MembershipGrid" runat="server" AllowPaging="False" 
            AllowSorting="False" AutoGenerateColumns="False" 
            DataKeyNames="membershipId" 
            CssClass="table table-striped table-condensed table-memberships"
            EnableViewState="false"
            BorderStyle="None"
            data-rowlink="a" CellSpacing="-1" GridLines="None"
            AutoGenerateEditButton="false">
            <Columns>
                <asp:TemplateField  HeaderText="" SortExpression="" HeaderStyle-CssClass="">
                    <ItemTemplate>
                         <a title="Edit" href='AddEditMember.aspx?mode=edit&membershipId=<%# Eval("membershipId") %>&displayName=<%# Eval("firstName") %>+<%# Eval("lastName") %>'><i class="splashy-document_letter_edit"></i></a>
                    </ItemTemplate>
                </asp:TemplateField>
                
                <asp:BoundField DataField="membershipType" HeaderText="Type" 
                    SortExpression="membershipType" />
                <asp:BoundField DataField="firstName" HeaderText="First Name" 
                    SortExpression="firstName" />
                <asp:BoundField DataField="lastName" HeaderText="Last Name" 
                    SortExpression="lastName" />
                <asp:BoundField DataField="membershipExpiration" DataFormatString = "{0:d}" 
                    HeaderText="Exp" SortExpression="membershipExpiration" />
                <asp:BoundField DataField="phoneNumber" HeaderText="Phone" 
                    SortExpression="phoneNumber" />
                <asp:TemplateField  HeaderText="Email" SortExpression="Email">
                    <ItemTemplate>
                        <a href="Mailto:<%# Eval("Email") %>"><%# Eval("Email") %></a>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="address" HeaderText="Address" 
                    SortExpression="address" />
                <asp:BoundField DataField="city" HeaderText="City" SortExpression="City" />
                <asp:BoundField DataField="state" HeaderText="State" SortExpression="State" />
                <asp:BoundField DataField="postalCode" HeaderText="Zip" 
                    SortExpression="postalCode" />
<%--                <asp:BoundField DataField="PaperNewsletter" 
                    HeaderText="Mail?" SortExpression="sendPaperNewsletter" />
                <asp:BoundField DataField="ENewsletter" HeaderText="EMail?" 
                    SortExpression="sendENewsletter" />--%>
                <asp:BoundField DataField="Contact" HeaderText="Contact?" 
                    SortExpression="okayToContact" />
            </Columns>
<%--            
            <EmptyDataTemplate>
                No members found matching that search criteria.
            </EmptyDataTemplate>
--%>
        </asp:GridView>
    </div>
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="scripts" runat="server">
    <script type="text/javascript">
        // Set the sidebar orientation to the section and page 
        // of this document
        $(document).ready(function () {
            $('#viewMembers').addClass("active");
            $('#collapseOne').addClass("in");
        });

        // Build pretty data table for memberships table
        $(document).ready(function () {
            $('#ContentPlaceHolder1_MembershipGrid').dataTable({
                "sDom": "<'row-fluid'<'span12'fi>r>t<'row'<'span12'>>",
                "sPaginationType": "bootstrap",
                "aLengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]],
                "bPaginate": false,
                "aaSorting": [[4, "asc"]],
                "aoColumnDefs": [
                   { "bSortable": false, "aTargets": [0] }
                ],
                "bSortClasses": false
            });
        });

        $('#currentFields').click(function () {
            $('#ContentPlaceHolder1_Current').attr('checked', true);
        });

        $('#allFields').click(function () {
            $('#ContentPlaceHolder1_All').attr('checked', true);
        });

        $('#expirationFields').click(function () {
            $('#ContentPlaceHolder1_Expiration').attr('checked', true);
        });

        function formateDateAsMMDDYYYY(d) {
            return (d.getMonth() + 1) + '/' + d.getDate() + '/' + d.getFullYear();
        }

        function setStartAndEndDatesByMonthOffset(startMonthOffset, endMonthOffset) {
            var startDate = new Date();
            if (startMonthOffset != "") {
                startDate.setMonth(startDate.getMonth() + startMonthOffset);
            }

            var endDate = new Date();
            if (endMonthOffset != "") {
                endDate.setMonth(endDate.getMonth() + endMonthOffset);
            }

            $('#ContentPlaceHolder1_expStartDate').val(formateDateAsMMDDYYYY(startDate));
            $('#ContentPlaceHolder1_expEndDate').val(formateDateAsMMDDYYYY(endDate));        
        }

        $('#ContentPlaceHolder1_ExpSelector').change(function () {
            switch ($('#ContentPlaceHolder1_ExpSelector').val()) {
                case "LastMonth":
                    setStartAndEndDatesByMonthOffset(-1, "");
                    break;
                case "LastTwoMonths":
                    setStartAndEndDatesByMonthOffset(-2, "");
                    break;
                case "LastFourMontsh":
                    setStartAndEndDatesByMonthOffset(-4, "");
                    break;
                case "NextMonth":
                    setStartAndEndDatesByMonthOffset("", 1);
                    break;
                case "NextTwoMonths":
                    setStartAndEndDatesByMonthOffset("", 2);
                    break;
                case "NextFourMonths":
                    setStartAndEndDatesByMonthOffset("", 4);
                    break;

            }
        });
        
        function selectBetween() {
            $('#ContentPlaceHolder1_ExpSelector').val("Between");        
        }
        $('#ContentPlaceHolder1_expStartDate').click(selectBetween);
        $('#ContentPlaceHolder1_expEndDate').click(selectBetween);
    </script>
</asp:Content>
